package com.avicsafety.ezsystem.utils;
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DateTime {
    public DateTime() {
    }

    public static boolean checkDate(String date) {
        if (date != null && date.length() != 0) {
            String format = "((19|20)[0-9]{2})-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01]) ([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]";
            Pattern pattern = Pattern.compile(format);
            Matcher matcher = pattern.matcher(date);
            return matcher.matches();
        } else {
            return false;
        }
    }

    public static boolean checkDate(String date, DateTime.Format f) {
        SimpleDateFormat df = new SimpleDateFormat(getDateTimeFormat(f));
        Date d = null;

        try {
            d = df.parse(date);
        } catch (Exception var5) {
            return false;
        }

        String s1 = df.format(d);
        return date.equals(s1);
    }

    public static Date getDate() {
        return getDate((DateTime.Format)null);
    }

    public static Date getDate(DateTime.Format f) {
        if (f == null) {
            return new Date();
        } else {
            SimpleDateFormat df = new SimpleDateFormat(getDateTimeFormat(f));
            Date d = new Date();

            try {
                d = df.parse(d.toString());
            } catch (Exception var4) {
                ;
            }

            return d;
        }
    }

    public static Date getDate(DateTime.Format f, String _dateTime) {
        SimpleDateFormat df = new SimpleDateFormat(getDateTimeFormat(f));

        Date temp_d;
        try {
            temp_d = df.parse(_dateTime);
        } catch (ParseException var5) {
            var5.printStackTrace();
            temp_d = null;
        }

        return temp_d;
    }

    private static String getDateTimeFormat(DateTime.Format f) {
        if (f.equals(DateTime.Format.full)) {
            return "yyyy-MM-dd HH:mm:ss";
        } else if (f.equals(DateTime.Format.sfull)) {
            return "yyyy-M-d H:m:s";
        } else if (f.equals(DateTime.Format.yyyymmdd)) {
            return "yyyy-MM-dd";
        } else if (f.equals(DateTime.Format.yyyymd)) {
            return "yyyy-M-d";
        } else if (f.equals(DateTime.Format.yymmdd)) {
            return "yy-MM-dd";
        } else if (f.equals(DateTime.Format.yymd)) {
            return "yy-M-d";
        } else if (f.equals(DateTime.Format.mmdd)) {
            return "MM-dd";
        } else if (f.equals(DateTime.Format.md)) {
            return "M-d";
        } else {
            return f.equals(DateTime.Format.yyyymm) ? "yyyy-MM" : "";
        }
    }

    public static int getDay() {
        Calendar c = Calendar.getInstance();
        return c.get(5);
    }

    public static int getDay(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(5);
    }

    public static int getDayCountByMonth(int _year, int _month) {
        int[] monthDay = new int[]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        if (_year % 4 == 0 && _year % 100 != 0 || _year % 400 == 0) {
            ++monthDay[1];
        }

        return monthDay[_month - 1];
    }

    public static int getHour() {
        Calendar c = Calendar.getInstance();
        return c.get(11);
    }

    public static int getHour(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(11);
    }

    public static int getMillisecond() {
        Calendar c = Calendar.getInstance();
        return c.get(14);
    }

    public static int getMinute() {
        Calendar c = Calendar.getInstance();
        return c.get(12);
    }

    public static int getMonth() {
        Calendar c = Calendar.getInstance();
        c.setTime(getDate(DateTime.Format.full));
        return c.get(2) + 1;
    }

    public static int getMonth(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(2) + 1;
    }

    public static int getMinute(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(12);
    }

    public static int getSecond() {
        Calendar c = Calendar.getInstance();
        return c.get(13);
    }

    public static String getStrDate(DateTime.Format f) {
        SimpleDateFormat df = new SimpleDateFormat(getDateTimeFormat(f));
        return df.format(getDate());
    }

    public static String getStrDate(DateTime.Format f, Date _datetime) {
        SimpleDateFormat df = new SimpleDateFormat(getDateTimeFormat(f));
        return df.format(_datetime);
    }

    public static String getStrDate(DateTime.Format f, long _datetime) {
        SimpleDateFormat df = new SimpleDateFormat(getDateTimeFormat(f));
        Date d = new Date(_datetime);
        return df.format(d);
    }

    public static String getStrDate(DateTime.Format f, DateTime.Format sourcef, String _datetime) {
        new SimpleDateFormat(getDateTimeFormat(sourcef));
        SimpleDateFormat df2 = new SimpleDateFormat(getDateTimeFormat(f));
        String _dateTime = "";
        Date _date = null;
        _date = getDate(sourcef, _datetime);
        return df2.format(_date);
    }

    public static String getStrDate(DateTime.Format f, int Interval) {
        Calendar c = Calendar.getInstance();
        c.add(5, Interval);
        SimpleDateFormat df = new SimpleDateFormat(getDateTimeFormat(f));
        return df.format(c.getTime());
    }

    public static int getTimeDiff(Date d1, Date d2) {
        long _diff = d2.getTime() - d1.getTime();
        int _temp = Math.round((float)(_diff / 1000L));
        return _temp;
    }

    public static int getTimeDiff(String d1, String d2) {
        boolean var2 = false;

        int _temp;
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date _d1 = df.parse(d1);
            Date _d2 = df.parse(d2);
            long _diff = _d2.getTime() - _d1.getTime();
            _temp = Math.round((float)(_diff / 1000L));
        } catch (ParseException var8) {
            _temp = -1;
            var8.printStackTrace();
        }

        return _temp;
    }

    public static int getYear() {
        Calendar c = Calendar.getInstance();
        c.setTime(getDate(DateTime.Format.full));
        return c.get(1);
    }

    public static int getYear(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(1);
    }

    public static String getNowDate(DateTime.Format f) {
        SimpleDateFormat df = new SimpleDateFormat(getDateTimeFormat(f));
        return df.format(getDate(f));
    }

    public static Date stringToDate(String strTime, DateTime.Format f) throws ParseException {
        SimpleDateFormat formatter = new SimpleDateFormat(getDateTimeFormat(f));
        Date date = null;
        date = formatter.parse(strTime);
        return date;
    }

    public static long stringToLong(String strTime, DateTime.Format f) throws ParseException {
        Date date = stringToDate(strTime, f);
        if (date == null) {
            return 0L;
        } else {
            long currentTime = dateToLong(date);
            return currentTime;
        }
    }

    public static long dateToLong(Date date) {
        return date.getTime();
    }

    public static String longToString(long millis, DateTime.Format f) {
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(millis);
        SimpleDateFormat df = new SimpleDateFormat(getDateTimeFormat(f));
        return df.format(cal.getTime());
    }

    public static Date getMondayDayOfWeek() {
        Calendar c = Calendar.getInstance();
        int dayofweek = c.get(7) - 1;
        if (dayofweek == 0) {
            dayofweek = 7;
        }

        c.add(5, -dayofweek + 1);
        c.set(11, 0);
        c.set(12, 0);
        c.set(13, 0);
        c.set(14, 0);
        new SimpleDateFormat("yyyy-MM-dd");
        return c.getTime();
    }

    public static Date getSunDayOfWeek() {
        Calendar c = Calendar.getInstance();
        int dayofweek = c.get(7) - 1;
        if (dayofweek == 0) {
            dayofweek = 7;
        }

        c.add(5, -dayofweek + 7);
        c.set(11, 23);
        c.set(12, 59);
        c.set(13, 59);
        c.set(14, 0);
        new SimpleDateFormat("yyyy-MM-dd");
        return c.getTime();
    }

    public static String subDate(String date) {
        try {
            Date currentDate = stringToDate(date, DateTime.Format.full);
            String times = getStrDate(DateTime.Format.yymmdd, currentDate);
            String[] dateArray = times.split("-");
            String dateStr = dateArray[1] + "/" + dateArray[2] + "/" + dateArray[0];
            return dateStr;
        } catch (ParseException var5) {
            var5.printStackTrace();
            return null;
        }
    }

    public static String showymdDate(String date) {
        if (date == null) {
            return "";
        } else {
            try {
                Date currentDate = stringToDate(date, DateTime.Format.full);
                String times = getStrDate(DateTime.Format.yyyymmdd, currentDate);
                return times;
            } catch (ParseException var3) {
                var3.printStackTrace();
                return null;
            }
        }
    }

    public static boolean isNow(String time) {
        Date date = getDate(DateTime.Format.full, time);
        Date now = new Date();
        SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
        String nowDay = sf.format(now);
        String day = sf.format(date);
        return day.equals(nowDay);
    }

    public static boolean isYesterday(String time) {
        Date date = getDate(DateTime.Format.full, time);
        Date now = new Date();
        SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
        String yesterday = sf.format(new Date(now.getTime() - 86400000L));
        String day = sf.format(date);
        return day.equals(yesterday);
    }

    public static enum Format {
        full,
        md,
        mmdd,
        sfull,
        yymd,
        yymmdd,
        yyyymd,
        yyyymmdd,
        yyyymm;

        private Format() {
        }
    }
}
